package com.bwie.controller;

import com.bwie.common.domain.User;
import com.bwie.common.domain.response.UserLoginRes;
import com.bwie.common.result.Result;
import com.bwie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.OutputStream;

/**
 * @className: UserService
 * @Description: TODO
 * @version: v1.８.0
 * @author: 汪菲阳
 * @date: 2025/10/22 9:28
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 图片验证码
     */
    @PostMapping("getImageCode")
    public void getImageCode(OutputStream outputStream){
       userService.getImageCode(outputStream);
    }

    /**
     * 发送验证码
     * @param userPhone
     * @return
     */
    @GetMapping("sendCode/{userPhone}")
    public Result sendCode(@PathVariable("userPhone") String userPhone){
        userService.sendCode(userPhone);
        return Result.success();
    }

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("login")
    public Result<UserLoginRes> login(@RequestBody @Valid User user){
        UserLoginRes userLoginRes=userService.login(user);
        return Result.success(userLoginRes);
    }

    /**
     * 校验图文验证码
     * @param imgCode
     * @return
     */
    @GetMapping("redisImgCode/{imgCode}")
    public Result redisImgCode(@PathVariable("imgCode") String imgCode){
        userService.redisImgCode(imgCode);
        return Result.success();
    }

    /**
     * 保存角色
     * @return
     */
    @GetMapping("saleRole/{roleId}")
    public Result saleRole(@PathVariable("roleId") Integer roleId){
        userService.saleRole(roleId);
        return Result.success();
    }
}
